/*
 * 6.4.cpp 1833
 *
 *  Created on: 2012-5-20
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define SIZE 1024

int arr[SIZE+10];

int n, k;

int compare(const void *a, const void *b) {
	return (*((int *)a) - *((int *)b));
}

void nextArr (int *start) {
	int j = n-1;
	while (j) {
		if (start[j-1] < start[j])
			break;
		j--;
	}
	if (j==0) {
		for (int i=0; i<n; i++) {
			start[i] = i+1;
		}
		return;
	}
	int minMax = j;
	for (int i=j; i<n; i++) {
		if (start[i] > start[j-1] && start[i] < start[minMax]) {
				minMax = i;
		}
	}
	start[j-1] = start[j-1] + start[minMax] - (start[minMax] = start[j-1]);
	qsort(start+j, n-j, sizeof(int), compare);
	return;
}

int main (void) {
	int cases;
	scanf("%d", &cases); //用cin可能造成超时
	while (cases--) {
		scanf("%d%d", &n, &k);
		for (int i=0; i<n; i++)
			scanf("%d", &arr[i]);
		while (k--)
			nextArr(arr);
			//next_permutation(arr, arr+n);
		for (int i=0; i<n; i++)
			cout << arr[i] << " ";
		cout << endl;
	}
	return 0;
}
